/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAFullRecord.m
//  redia-bapps-ios
//
//  Created by Nikolaj Tørring on 8/7/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BAFullRecord.h"
#import "JSONEncodingHelperMethods.h"
#import "BAHoldingContainer.h"

@implementation BAFullRecord

+ (id)objectWithJSONObject:(NSDictionary *)jsonObj
{
    BAFullRecord *obj = [BAFullRecord new];
    
    obj.title = [JSONEncodingHelperMethods parseStringWithKey:@"title" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.title);
    obj.identifier = [JSONEncodingHelperMethods parseStringWithKey:@"identifier" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.identifier);
    obj.faust = [JSONEncodingHelperMethods parseStringWithKey:@"faust" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.faust);
    
    obj.moreInSameSeries = [JSONEncodingHelperMethods parseBoolWithKey:@"moreInSameSeries" fromJsonObject:jsonObj];

    obj.isbn = [JSONEncodingHelperMethods parseStringWithKey:@"isbn" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.isbn);
    
    obj.creators = [JSONEncodingHelperMethods parseArrayOfStringsWithKey:@"creators" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSArray, obj.creators);
    obj.type = [JSONEncodingHelperMethods parseStringWithKey:@"type" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.type);
    obj.shelfmark = [JSONEncodingHelperMethods parseStringWithKey:@"shelfmark" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.shelfmark);
    obj.publisher = [JSONEncodingHelperMethods parseStringWithKey:@"publisher" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.publisher);
    obj.edition = [JSONEncodingHelperMethods parseStringWithKey:@"edition" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.edition);
    obj.year = [JSONEncodingHelperMethods parseStringWithKey:@"year" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.year);
    obj.language = [JSONEncodingHelperMethods parseStringWithKey:@"language" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.language);
    obj.abstract = [JSONEncodingHelperMethods parseStringWithKey:@"abstract" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.abstract);
    obj.subjects = [JSONEncodingHelperMethods parseArrayOfStringsWithKey:@"subjects" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSArray, obj.subjects);
    
    
    obj.isERessource = [JSONEncodingHelperMethods parseBoolWithKey:@"isERessource" fromJsonObject:jsonObj];

    obj.eRessourceUrl = [JSONEncodingHelperMethods parseStringWithKey:@"eRessourceUrl" fromJsonObject:jsonObj];
    if (obj.eRessourceUrl) {
        EXPECT_OBJECT(NSString, obj.eRessourceUrl);
    }
    
    obj.availability = [JSONEncodingHelperMethods parseObjectOfClass:[BAAvailability class] withKey:@"availability" fromJsonObject:jsonObj];
    if (obj.availability != nil) {
        //FIXME: backend should never provide nil
        EXPECT_OBJECT(BAAvailability, obj.availability);
    }
    
    obj.nofReservations = [JSONEncodingHelperMethods parseIntegerWithKey:@"nofReservations" fromJsonObject:jsonObj];

    obj.seriesInfo = [JSONEncodingHelperMethods parseStringWithKey:@"seriesInfo" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.seriesInfo);

    return obj;
}

-(NSDictionary *)toJSONObject{
    DLog(@"Not implemented");
    return nil;
}

@end
